import 'package:flutter/material.dart';
import 'package:flutter_shop/jpush/jpush_service.dart';
import 'package:flutter_shop/pages/base/base_state_less_widget.dart';
import 'package:flutter_shop/pages/member/member_router.dart';
import 'package:flutter_shop/pages/member/member_tab_page/member_tab_presenter.dart';
import 'package:flutter_shop/r.dart';
import 'package:flutter_shop/res/styles.dart';
import 'package:flutter_shop/routers/navigator_utils.dart';
import 'package:flutter_shop/utils/log_utils.dart';
import 'package:flutter_shop/utils/utils.dart';
import 'package:flutter_shop/widget/custom_dialog.dart';
import 'package:flutter_shop/widget/single_line_item.dart';

///测试第三方
class TestThird extends BaseStateLessWidget<MemberTabPresenter> {
  ///极光推送别名
  String _jpushAlias = "";

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            padding: Paddings.common,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              color: Colors.white,
              border: Borders.bottom,
            ),
            child: Text("集成第三方"),
          ),
          SingleLineItem(
            leftImage: R.assetsImgLogo,
            leftText: "高德地图",
            onPressed: () {
              NavigatorUtils.push(context, MemberRouter.myMap);
            },
          ),
          StatefulBuilder(builder: (context, setState) {
            return SingleLineItem(
              leftImage: R.assetsImgLogo,
              leftText: "极光推送",
              rightText: Utils.strIsEmpty(_jpushAlias) ? "" : "别名:$_jpushAlias",
              hint: "请输入",
              onPressed: () async {
                showDialog(
                  context: context,
                  builder: (context) => InputDialog(
                    _jpushAlias,
                    title: "设置别名",
                    hintText: "请输入别名",
                    canBackDismiss: false,
                    autoConfirmClose: false,
                    inputType: InputDialog.INPUT_TYPE_ARR[3],
                    confirmCallback: (String content) async {
                      if (Utils.strIsEmpty(content)) {
                        Utils.showToast("请输入别名");
                        return;
                      }
                      Navigator.pop(context);
                      String rid = await JpushService().getRegistrationID();
                      Map<dynamic, dynamic> aliasMap = await JpushService().setAlias(content);
                      Log.d(rid, tag: "JpushService");
                      Log.json(Utils.parseObj2Json(aliasMap), tag: "JpushService");
                      Utils.showToast("rid=$rid\n别名:${Utils.parseObj2Json(aliasMap)}");

                      setState(() {
                        _jpushAlias = content;
                      });
                    },
                  ),
                );
              },
            );
          }),
        ],
      ),
    );
  }
}
